package com.jin.api.v1;
import com.jin.Exception.http.NotFoundException;
import com.jin.core.interceptors.ScopeLevel;
import com.jin.model.Banner;
import com.jin.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
//为了规范性但是又不想每一次写路由的时候都加上包的前缀才开发了自动拼接路由的类
//v1包存在的目的是为了后期方便维护或者进行推展是必须的，所以路由也要进行规范的编写



@RestController
@RequestMapping("/banner")
@Validated //对传入参数进行校验的注解
public class BannerController {
   @Autowired
   BannerService bannerService;

    @GetMapping("/name/{name}")
    //@ScopeLevel
    public Banner getByName(@PathVariable @NotBlank String name){
        Banner banner = bannerService.getByName(name);
        if (banner == null){
            throw new NotFoundException(30005);
        }
        return banner;
    }

}


